package com.steakliu.sun.protocol.generate;

import com.steakliu.sun.constant.SunConstant;
import com.steakliu.sun.protocol.MsgHeader;
import com.steakliu.sun.protocol.MsgStatus;
import com.steakliu.sun.protocol.MsgType;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 功能说明： 协议头生成器
 * <p>
 * Original @Author: steakliu-刘牌, 2023-01-08  16:54
 * <p>
 * Copyright (C)2020-2022  steakliu All rights reserved.
 */
public class MsgHeaderGenerator {

    private static final AtomicInteger AUTO = new AtomicInteger(0);

    public static MsgHeader generateMsgHeader(String serializer, MsgType msgType){
        MsgHeader header = new MsgHeader();
        header.setMagic(SunConstant.MAGIC);
        header.setType((byte) msgType.getType());
        header.setRequestId(AUTO.incrementAndGet());
        header.setSerializer(serializer);
        header.setStatus((byte) MsgStatus.SUCCESS.getStatus());
        return header;
    }
}
